<template>
  <!-- 查看详情 2018/3/7 11:44 zhangQ -->
  <div>
    <div>
      <tablePage ref="subOrderTab" :staticData="subOrderData" :isStartLoad="false" :mode="1">
        <template slot-scope="props">
          <Table :columns="subOrderColumn" border :data="props.data" @on-sort-change="props.sortChange"></Table>
        </template>
      </tablePage>
    </div>
  </div>
</template>

<script>
  import {getOrderDetail} from '@api/backEnd/mainOrder'
  import tablePage from '@components/table/tablePage.vue'
  import xlinkModal from '@components/modal/xlinkModal'
  import moment from 'moment'

  export default {
    name: 'view-detail',
    data () {
      let subOrderColumn = [
        {
          title: '子订单单号',
          ellipsis: 'false',
          key: 'orderNo',
          width: 200
        },
        {
          title: '箱号',
          ellipsis: 'false',
          key: 'containerNoBody',
          width: 200,
          render: (h, params) => {
            let containerNo = params.row.containerNoHead + params.row.containerNoBody
            return (<span>{containerNo}</span>)
          }
        },
        {
          title: '拉运车号',
          ellipsis: 'false',
          width: 150,
          key: 'truckPlate'
        },
        {
          title: '重箱出场时间',
          ellipsis: 'false',
          key: 'bindTime',
          width: 250,
          render: (h, params) => {
            let thisdata = params.row.bindTime
            thisdata = thisdata ? moment(thisdata).format('YYYY-MM-DD HH:mm') : ''
            return (<span>{thisdata}</span>)
          }
        },
        {
          title: '车队名称',
          ellipsis: 'false',
          width: 150,
          key: 'fleetName'
        },
        {
          title: '司机名称',
          ellipsis: 'false',
          width: 150,
          render: (h, params) => {
            return (<span title={params.row.driverName}>{params.row.driverName}</span>)
          }
        },
        {
          title: '送货地址',
          ellipsis: 'false',
          key: 'shippingAddress',
          width: 150,
          render: (h, params) => {
            return (<span title={params.row.shippingAddress}>{params.row.shippingAddress}</span>)
          }
        }
      ]
      let noticeRecordColumn = [
        {
          title: '车队名称',
          ellipsis: 'false',
          key: 'fleetName'
        },
        {
          title: '送货地址',
          ellipsis: 'false',
          key: 'addresses'
        }
      ]
      let ImgModel = false
      let subOrderData = []
      let positionList = []
      let noticeRecordData = []
      let currentName = '1'
      let lookImtList = []
      let datas = {currentName, subOrderColumn, subOrderData, positionList, noticeRecordColumn, noticeRecordData, ImgModel, lookImtList}
      return datas
    },
    props: {
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      /**
       * TODO(获得子订单信息)
       * @auther zhangQ
       * @date 2018/3/16 15:40
       **/
      getSubOrderData () {
        if (!(this.currentMainOrder && this.currentMainOrder.orderNo)) {
          return
        }
        let param = {
          orderNo: this.currentMainOrder.orderNo
        }
        getOrderDetail(param).then(res => {
          if (res.data.isSuccess === 1) {
            this.subOrderData = res.data.data.sub
            this.positionList = res.data.data.position
          } else {
            Promise.reject(new Error(res.data.res))
          }
        }).catch((err) => {
          console.log('接口getOrderDetail:' + err)
        })
      }
    },
    mounted () {
      this.getSubOrderData()
    },
    components: {tablePage, xlinkModal}
  }
</script>
